home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Grafik & Text / OzTeX3.0 / TeX-inputs / LaTeX / contrib / answers.sty < prev    next >
Text File  |  1997-03-26  |  5KB  |  195 lines

  1. %%
  2. %% This is file `answers.sty',
  3. %% generated with the docstrip utility.
  4. %%
  5. %% The original source files were:
  6. %%
  7. %% answers.dtx  (with options: `answers')
  8. %% 
  9. %% Copyright (C) 1990,1994 Mike Piff, University of Sheffield, England
  10. %% 
  11. %% You are not allowed to change this file.
  12. %% 
  13. %% You are NOT ALLOWED to distribute this file alone.  You are NOT
  14. %% ALLOWED to take money for the distribution or use of this
  15. %% file except for a nominal charge for copying etc.
  16. %% 
  17. %% Please address any problems to:
  18. %% 
  19. %% M.Piff@shef.ac.uk
  20. %% 
  21. %% For updates, contact your nearest CTAN site.
  22. %% 
  23. \def\fileversion{2.09}
  24. \def\filedate{10 Jul 1996 16:36:03 BST}
  25. \def\filename{answers.dtx}
  26. \def\Copyright{Copyright (C) 1990,1994 Mike Piff,
  27.    University of Sheffield, England}
  28. \NeedsTeXFormat{LaTeX2e}[1996/06/01]
  29. \ProvidesPackage{answers}[1996/07/10]
  30. \typeout{Package `answers' <\filedate>.}
  31. \typeout{\Copyright}
  32. \newif\ifanswerfiles \answerfilestrue
  33. \DeclareOption{nosolutionfiles}{\answerfilesfalse
  34.    \typeout{No answer files being produced}}%
  35. \ProcessOptions
  36.  
  37. \RequirePackage{verbatim}
  38. \newcommand{\solutionextension}{tex}
  39. \newenvironment{Filesave}[1]{%
  40.    \@bsphack
  41.    \def\verbatim@processline{}%
  42.    \Iffileundefined{#1}{}{%
  43.       \Ifopen{#1}{%
  44.          \def\verbatim@processline{%
  45.             \Ifanswerfiles{%
  46.                \immediate\write\@nameuse{#1@file}%
  47.                   {\the\verbatim@line}%
  48.             }{}%
  49.          }%
  50.       }{}%
  51.    }%
  52.    \let\do\@makeother\dospecials
  53.    \catcode`\^^M\active \catcode`\^^I=12\relax
  54.    \verbatim@start
  55. }{\@esphack}
  56. \newcommand{\Writetofile}[2]{%
  57.    \@bsphack
  58.    \Iffileundefined{#1}{}{%
  59.       \Ifopen{#1}{%
  60.          {%
  61.             \let\protect\string
  62.             \Ifanswerfiles{%
  63.                \immediate\write\@nameuse{#1@file}{#2}%
  64.             }{}%
  65.          }%
  66.       }{}%
  67.    }%
  68.    \@esphack
  69. }
  70. \newcommand{\Ifopen}[3]{%
  71.    \csname if#1open\endcsname#2\else#3\fi}%
  72. \newcommand{\Iffileundefined}[3]{%
  73.    \csname ifx\expandafter\endcsname
  74.       \csname #1@file\endcsname\relax
  75.       #2\else#3\fi}
  76. \newcommand{\Ifanswerfiles}[2]{%
  77.    \ifanswerfiles #1\else #2\fi}
  78. \def\Opensolutionfile#1{%
  79.    \@ifnextchar[{\define@filename{#1}}%
  80.       {\define@filename{#1}[#1]}}%
  81. \def\define@filename#1[#2]{%
  82.    \global\@namedef{#1@filename}{#2.\solutionextension}%
  83.    \Ifanswerfiles{%
  84.       \typeout{Output from handle #1 going
  85.          to #2.\solutionextension}%
  86.    }{}%
  87.    \Iffileundefined{#1}{%
  88.       \expandafter\newwrite\csname #1@file\endcsname
  89.       \csname newif\expandafter\endcsname
  90.          \csname if#1open\endcsname
  91.       \global\csname #1openfalse\endcsname
  92.       \expandafter\ifx\csname Open#1hook\endcsname\relax
  93.          \global\@namedef{Open#1hook}##1{}%
  94.       \fi
  95.       \expandafter\ifx\csname Close#1hook\endcsname\relax
  96.          \global\@namedef{Close#1hook}##1{}%
  97.       \fi
  98.    }{}%
  99.    \let\Tmp\relax
  100.    \Ifopen{#1}{\typeout{File #1 already open}}{%
  101.       \Ifanswerfiles{%
  102.          \immediate\openout\@nameuse{#1@file}=%
  103.          \@nameuse{#1@filename}%
  104.       }{}%
  105.       \global\csname#1opentrue\endcsname
  106.       \def\Tmp{\@nameuse{Open#1hook}{#1}}%
  107.    }%
  108.    \Tmp
  109. }
  110. \def\Closesolutionfile#1{%
  111.    \let\Tmp\relax
  112.    \Iffileundefined{#1}{}{%
  113.       \Ifopen{#1}{%
  114.          \Ifanswerfiles{%
  115.             \immediate\closeout\@nameuse{#1@file}%
  116.          }{}%
  117.          \global\csname #1openfalse\endcsname
  118.          \def\Tmp{\@nameuse{Close#1hook}{#1}}%
  119.       }{}%
  120.    }%
  121.    \Tmp
  122. }
  123. \def\Readsolutionfile#1{%
  124.    \Ifanswerfiles{%
  125.       \Iffileundefined{#1}{}{%
  126.          \Ifopen{#1}{%
  127.             \typeout{WARNING: attempt to read open file #1}%
  128.          }{%
  129.             \edef\Tmp{%
  130.                \noexpand\InputIfFileExists
  131.                   {\@nameuse{#1@filename}}{}%
  132.                {\noexpand\message{File
  133.                   \@nameuse{#1@filename}%
  134.                      \space not found}}%
  135.             }%
  136.             \Tmp
  137.          }%
  138.       }%
  139.    }{}%
  140. }
  141.  
  142. \newcommand{\Newassociation}[3]{%
  143.    \newsolution{#2}%
  144.    \expandafter\ifx\csname #3opentrue\endcsname\relax
  145.       \expandafter\newif\csname if#3open\endcsname
  146.    \fi
  147.    \newenvironment{#1}{%
  148.       \Ifanswerfiles{%
  149.          \let\Tmp\relax
  150.          \Iffileundefined{#3}{}{%
  151.             \Ifopen{#3}{%
  152.                \immediate\write\@nameuse{#3@file}%
  153.                   {\string\begin{#2}\@nameuse{#2params}}%
  154.             \def\Tmp{\Filesave{#3}}%
  155.             }{}%
  156.          }%
  157.       }{%
  158.          \edef\Tmp{\noexpand\begin{#2}\@nameuse{#2params}}%
  159.       }%
  160.       \csname pre#1\endcsname
  161.       \Tmp
  162.    }%
  163.    {%
  164.       \Ifanswerfiles{%
  165.          \Iffileundefined{#3}{}{%
  166.             \Ifopen{#3}{%
  167.                \endFilesave%
  168.                \immediate\write\@nameuse{#3@file}%
  169.                   {\string\end{#2}}%
  170.                \csname post#1\endcsname
  171.             }{}%
  172.          }%
  173.       }{%
  174.          \end{#2}%
  175.       }%
  176.    }%
  177. }
  178. \newcommand{\newsolution}[1]{%
  179.    \@ifundefined{#1}{%
  180.       \global\@namedef{#1params}{{\Currentlabel}}%
  181.       \newenvironment{#1}[1]%
  182.       {%
  183.          \csname pre#1\endcsname
  184.          \trivlist
  185.          \item[\hskip\itemsep{\@nameuse{#1label}{##1}}]}%
  186.       {\csname post#1\endcsname\endtrivlist}%
  187.       \global\@namedef{#1label}##1{\solutionstyle{##1}}%
  188.    }{\typeout{WARNING: environment #1 already in use}}%
  189. }
  190. \newcommand{\solutionstyle}[1]{\textbf{#1}}
  191. \newcommand{\Currentlabel}{\@currentlabel}
  192. \endinput
  193. %%
  194. %% End of file `answers.sty'.
  195.